package com.lzyjkz.quick_components.advice;


import com.lzyjkz.quick_components.entity.Response;
import com.lzyjkz.quick_components.exceptions.IllegalRequestParamException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import com.lzyjkz.quick_components.exceptions.LoginExpiredException;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionInterceptor {

    @ExceptionHandler(IllegalRequestParamException.class)
    public Response<String> GlobalException(IllegalRequestParamException e){
        return Response.fail(e.getMessage());
    }

    @ExceptionHandler(LoginExpiredException.class)
    public Response<String> GlobalException(LoginExpiredException e){
        return Response.fail(401, e.getMessage());
    }

//    @ExceptionHandler(Exception.class)
//    public Response<String> GlobalException(Exception e){
//        log.error("异常类型：{}，异常信息：{}", e.getClass(), e.getMessage(), e.getCause());
//        e.printStackTrace();
//        return Response.fail(e.getMessage());
//    }
}
